package com.bawei.composeui2207a.day03

import android.annotation.SuppressLint
import androidx.compose.foundation.Image
import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import com.bawei.composeui2207a.R
import com.bawei.composeui2207a.view.HomePage
import com.bawei.composeui2207a.view.MinePage

/**
 * 作者：赵亮
 * 时间：2024/12/12 11:48
 * 功能：脚手架 - 底部导航
 */

data class BottomEntity(val img: Int, val text: String)

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
@Composable
fun Day03_2() {

    // 底部导航对应的数据
    val list = listOf(
        BottomEntity(R.drawable.icon1275, "消息"),
        BottomEntity(R.drawable.icon64, "门户"),
        BottomEntity(R.drawable.icon1405, "我的"),
    )

    // 底部导航选中的位置
    var selectedIndex by remember {
        mutableStateOf(0)
    }

    Scaffold(bottomBar = {
        // 底部导航
        NavigationBar {
            list.forEachIndexed { index, it ->
                NavigationBarItem(
                    label = { Text(text = it.text) },
                    selected = selectedIndex == index,
                    onClick = { selectedIndex = index },
                    icon = { Image(painter = painterResource(id = it.img), contentDescription = null) })
            }
        }
    }) {
        // 页面
        when(selectedIndex) {
            0 -> Day03_1()
            1 -> HomePage()
            2 -> MinePage()
        }
    }
}

@Preview(showSystemUi = true)
@Composable
fun Day03_2Preview() {
    Day03_2()
}

